﻿#-*- encoding: utf-8 -*-

import gdata.photos.service
import gdata.media
import gdata.geo
import Image
import os, glob, sys, getpass

in_ec = sys.stdin.encoding

gd_client = gdata.photos.service.PhotosService()
gd_client.email = raw_input('Input your username.')
gd_client.password = getpass.getpass('Input your password.')
gd_client.source = 'ley\'s photo uploader'
gd_client.ProgrammaticLogin()


ab_title = raw_input('Input your album\'s title.').decode(in_ec).encode('utf-8')
ab_discription = raw_input('Input your album\'s description.').decode(in_ec).encode('utf-8')
  
album = gd_client.InsertAlbum(title=ab_title, summary=ab_discription, access="private")

out_dir = './out/'
for image in glob.glob(out_dir + '*.jpg'):
	title = os.path.split(image)[1]
	gd_client.InsertPhotoSimple(
    '/data/feed/api/user/%s/albumid/%s' %('default', album.gphoto_id.text), title, 
    '', image, content_type='image/jpeg')

albums = gd_client.GetUserFeed(user='leydemail@gmail.com')
for a in albums.entry:	
	if a.gphoto_id.text == album.gphoto_id.text:
		print 'title: %s, number of photos: %s, id: %s' % (a.title.text, a.numphotos.text, a.gphoto_id.text)
		a.access.text = 'private'
		album_updated = gd_client.Put(a, a.GetEditLink().href, converter=gdata.photos.AlbumEntryFromString) 
	
#album = gd_client.GetEntry('/data/feed/api/user/%s/albumid/%s' % ('default', album.gphoto_id.text))
#album.access.text = 'public'
#album_updated = gd_client.Put(album, album.GetEditLink().href, converter=gdata.photos.AlbumEntryFromString) 